﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AdaptiveAgents.Loggers
{
    /// <summary>
    /// Represents a logger that contains a list of loggers
    /// </summary>
    public class ContainerLogger : Logger
    {
        private List<Logger> loggers; //list of loggers

        /// <summary>
        /// Constructor
        /// </summary>
        public ContainerLogger()
        {
            loggers = new List<Logger>();
        }

        /// <summary>
        /// Adds a new logger into loggers list
        /// </summary>
        /// <param name="logger"></param>
        public void Add(Logger logger) { loggers.Add(logger); }

        /// <summary>
        /// Close every outputstream of each logger in list
        /// </summary>
        public override void Close()
        {
            foreach (Logger logger in loggers)
                logger.Close();
        }

        /// <summary>
        /// Log the message in each logger in list
        /// </summary>
        /// <param name="message">message type</param>
        /// <param name="newLine">indication of writing a new line</param>
        /// <param name="p">array of data objects</param>
        protected override void writeInternal(MessageType message, bool newLine, params object[] p)
        {
            if (newLine)
                foreach (Logger logger in loggers)
                    logger.WriteLine(message, p);
            else
                foreach (Logger logger in loggers)
                    logger.Write(message, p);
        }
    }
}
